package com.cbd.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cbd.dto.QueryLogDto;
import com.cbd.entity.OpLogEntity;
import com.cbd.mapper.OpLogMapper;
import com.cbd.service.IOpLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author BingBing
 * @desc IOpLogService实现类
 * @date 2024/11/26 11:42
 */
@Service
@Slf4j
public class OpLogServiceImpl extends ServiceImpl<OpLogMapper, OpLogEntity> implements IOpLogService {

    private final int pageSize = 10;
    @Resource
    private OpLogMapper opLogMapper;

    /**
     * 查询日志列表
     * @param queryLogDto
     * @return 日志列表
     */
    @Override
    public List<OpLogEntity> queryByCondition(QueryLogDto queryLogDto) {
        int start = (queryLogDto.getPage() - 1) * pageSize;
        int end = pageSize;
        List<OpLogEntity> list = opLogMapper.queryByCondition(queryLogDto, start, end);
        log.info("查询日志列表，结果：{}", list);
        return list;
    }

    /**
     * 获取日志总页数
     * @return pageCount
     */
    @Override
    public int getPageCount(QueryLogDto queryLogDto) {
        int count = opLogMapper.getPageCount(queryLogDto);
        int pageCount = (count+pageSize-1) / pageSize;
        return pageCount;
    }
}
